<include file="Public:header" />
<!-- main content start-->
<div class="main-content" >

    <!-- header section start-->
    <div class="header-section">

        <!--toggle button start-->
        <a class="toggle-btn"><i class="fa fa-bars"></i></a>
        <!--toggle button end-->



        <!--notification menu start -->
        <div class="menu-right">
            <ul class="notification-menu" style="margin-top: 15px;">
                <li>
                <span class="span" style="margin-top: 100px;"><!-- data-toggle="dropdown"-->
                    账户余额(元)<span style="color: red; font-size: 16px; font-weight: 800 ">{$info.money}</span>
                </span>
                </li>
            </ul>
        </div>
    <!-- header section end-->
    <!-- page heading start-->
    <div class="page-heading">
        <h3>
            商户充值
        </h3>
        <ul class="breadcrumb">
            <li>
                <a href="#">首页</a>
            </li>
            <li> 商户管理 </li>
            <li class="active"> 商户充值 </li>
        </ul>
    </div>
    <!-- page heading end-->
    <!--body wrapper start-->
    <div class="wrapper">
        <section class="panel">
            <header class="panel-heading">
                商户充值
            </header>
            <div class="panel-body">
                <form class="form-horizontal" role="form" enctype="multipart/form-data" method="post" id="pay">

                    <div class="form-group">
                        <input type="hidden" name="shop_id" value="{$shop_id}">
                        <label class="col-md-2 col-sm-2 control-label">金额</label>
                        <div class="col-md-6 col-sm-6">
                            <input type="text" name="money" id="money" class="form-control" placeholder="金额">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 col-sm-2 control-label" style="padding-top: 30px;">充值方式</label>

                        <label class="btn btn-default" style="margin-right: 20px;">
                            <input type="radio" class="toggle" name="pay_type" value="1" > <img src="__PUBLIC__/shopadmin/images/alipay.jpg" height="100" width="100" alt="支付宝充值">
                        </label>
                        <label class="btn btn-default">
                            <input type="radio" name="pay_type" class="toggle" value="2"><img src="__PUBLIC__/shopadmin/images/weixin.jpg" height="100" width="100" alt="微信充值">
                        </label>
                    </div>
                    <img src="" width="400" height="400" id="wxcode" style="display: none;">
                    <div class="form-group">
                        <div class="col-lg-offset-2 col-md-6 col-sm-6">
                            <button data-id="chongzhi" type="button" class="btn btn-primary">充值</button>
                            <button type="button" class="btn btn-primary" onclick="history.go(-1)">返回</button>
                        </div>
                    </div>
                </form>
            </div>
        </section>


    </div>
    <!--body wrapper end-->
    <!-- main content end-->
    <script>
        $(function () {
            $("button[data-id='chongzhi']").click(function () {

                var money=$("#money").val();
                var pay_type=$('input[name="pay_type"]:checked ').val();
                if(money <= 0){
                    toast("充值金额不能小于0", false);
                    return false;
                }
                if (pay_type==1){
                    var alipayurl='{:U("/Shopadmin/Code/shop_alipay_pay")}';
                    window.location.href=alipayurl+"?money="+money;
                }
                else{
                    var url="{:U('/shopadmin/code/shop_weixin_pay')}";
                    $.post(url,{money:money},function (data) {
                        if(data.code==200){
                            $("#wxcode").attr('src',data.codeurl).show();
                        }
                        setInterval(function() {
                            setWeiXinCheck(data.order_number)
                        }, 3000);
                    });


                }
            })

            var succurl='{:U("/Shopadmin/Code/getPayStatus")}';
            var jumpurl='{:U("/Shopadmin/Login/info")}';

            function setWeiXinCheck (order_number) {
                $.post(succurl,{order_number:order_number},function (data) {
                    if(data.code==200){
                        toast("充值成功", true);
                        window.location.href=jumpurl;
                    }
                });
            }
        });

    </script>
    <include file="Public:footer" />